<template>
  <div class="userManagement-container">
    <el-row :gutter="20" class="index-container">
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <el-card shadow="never">
          <div slot="header">
            <span>视频操作审计图</span>
          </div>
          <vab-chart
            :autoresize="true"
            theme="vab-echarts-theme"
            :options="videoAudit"
          />
        </el-card>
      </el-col>
    </el-row>
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.name"
              placeholder="请输入视频名"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      :height="height"
      :element-loading-text="elementLoadingText"
    >
      <el-table-column show-overflow-tooltip prop="videoName" label="视频名称">
        <template slot-scope="scope">
          <el-popover trigger="click" placement="top" style="left: auto">
            <vab-chart
              v-loading="videoEditload"
              :autoresize="true"
              theme="vab-echarts-theme"
              :options="showedit"
            />
            <div slot="reference">
              <el-tag size="medium" @click="showVideoEdit(scope.row)">
                {{ scope.row.videoName }}
              </el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="textCount"
        label="文本数量"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="editTimes"
        label="修改次数"
      ></el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :page-size="queryForm.pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
    <edit ref="edit" @fetch-data="fetchData"></edit>
  </div>
</template>

<script>
  import Edit from './components/UserManagementEdit'
  import VabChart from '@/plugins/echarts'
  import { videoAuditgetList, getvideoEdit } from '@/api/audit'
  export default {
    name: 'VideosAudit',
    components: { Edit, VabChart },
    data() {
      return {
        videoEditload: false,
        videoId: 0,
        showedit: {
          grid: {
            top: '4%',
            left: '2%',
            right: '4%',
            bottom: '0%',
            containLabel: true,
          },
          xAxis: {
            type: 'time',
          },
          yAxis: {
            type: 'value',
            minInterval: 1,
          },
          series: [],
        },
        videoAudit: {
          grid: {
            top: '4%',
            left: '2%',
            right: '4%',
            bottom: '0%',
            containLabel: true,
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow',
            },
          },
          xAxis: [
            {
              type: 'category',
              /*boundaryGap: false,*/
              data: [],
              axisTick: {
                alignWithLabel: true,
              },
            },
          ],
          yAxis: [
            {
              type: 'value',
            },
          ],
          series: [
            {
              name: '文本数量',
              type: 'bar',
              emphasis: {
                focus: 'series',
              },
              data: [],
            },
            {
              name: '文本修改次数',
              type: 'bar',
              data: [],
            },
          ],
        },
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        elementLoadingText: '正在加载...',
        queryForm: {
          name: '',
          pageNo: 1,
          pageSize: 10,
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      async showVideoEdit(val) {
        const result = await getvideoEdit(val.videoId)
        let editList = result.data.data
        this.videoEditload = true
        let myseries = []
        if (editList !== null)
          for (let i = 0; i < editList.length; i++) {
            let temp = {}
            let stime = ['2021-3-3', 0]
            let etime = ['2021-3-3 ', 0]
            temp = {
              type: 'line',
              data: [],
            }
            stime[0] = stime[0] + editList[i].startTime.slice(3)
            etime[0] = etime[0] + editList[i].endTime.slice(3)
            etime[1] = stime[1] = editList[0].editTimes
            temp.data.push(stime)
            temp.data.push(etime)
            myseries.push(temp)
          }
        this.showedit.series = myseries
        setTimeout(() => {
          this.videoEditload = false
        }, 300)
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const query = await videoAuditgetList(this.queryForm)
        let data = query.data
        this.list = data.data
        this.total = data.totalResults
        let textSum = []
        let editTimes = []
        let xdata = []
        let ls = data.data
        for (let i = 0; i < ls.length; i++) {
          xdata.push(ls[i].videoName)
          textSum.push(ls[i].textCount)
          editTimes.push(ls[i].editTimes)
        }
        this.videoAudit.xAxis[0].data = xdata
        this.videoAudit.series[0].data = textSum
        this.videoAudit.series[1].data = editTimes
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      },
    },
  }
</script>
<style lang="scss" scoped>
  .index-container {
    padding: 0 !important;
    margin: 0 !important;

    ::v-deep {
      .el-card__body {
        .echarts {
          width: 100%;
          height: 115px;
        }
      }
    }

    .card {
      ::v-deep {
        .el-card__body {
          .echarts {
            width: 100%;
            height: 305px;
          }
        }
      }
    }

    .bottom {
      padding-top: 20px;
      margin-top: 5px;
      color: #595959;
      text-align: left;
      border-top: 1px solid $base-border-color;
    }

    .icon-panel {
      height: 117px;
      text-align: center;
      cursor: pointer;

      svg {
        font-size: 40px;
      }

      p {
        margin-top: 10px;
      }
    }

    .bottom-btn {
      button {
        margin: 5px 10px 15px 0;
      }
    }
  }
</style>
